Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Convert to String a map similar to console output via console.log([...mapObject.entries()])

I have the following map:

  let mapObject = new Map();
  mapObject.set("one", "file1");
  mapObject.set("two", "file2");
  mapObject.set("three", "file3");

  console.log([...mapObject.entries()]);

and the console generates the following output:

[ [ 'one', 'file1' ], [ 'two', 'file2' ], [ 'three', 'file3' ] ]

I took this idea from this post, but this solution doesn't work if you add a string in the console statement:

console.log("This is a map: " + [...mapObject.entries()]);

it generates the following output instead:

This is a map: one,file1,two,file2,three,file3

which is less friendly to read. I would like in some how to have the same output I would obtain from: console.log([...mapObject.entries()]) but to be able to store it in a string for a general purpose. Is there a simple way to achieve it that works for google apps script?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use JSON.stringify:

let mapObject = new Map();
mapObject.set("one", "file1");
mapObject.set("two", "file2");
mapObject.set("three", "file3");

const res = JSON.stringify([...mapObject.entries()])

console.log("This is a map: " + res);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!